package pro1.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import pro1.model.ResponseBody;
import pro1.service.DepartmentService;

@RestController
@RequestMapping("dep")
public class DepartmentController {

	@Autowired
	DepartmentService departmentService;

	/**
	 * 查询所有
	 * 
	 * @return
	 */
	@GetMapping("allDep")
	public ResponseBody allDep() {

		return departmentService.allDep();
	}

	/**
	 * 添加或删除
	 * 
	 * @param depId
	 * @param name
	 * @param info
	 * @return
	 */
	@PostMapping("addOrUpdateDep")
	public ResponseBody addOrUpdateDep(@RequestParam(value = "depId", required = false) Integer depId,
			@RequestParam(value = "name", required = false) String name,
			@RequestParam(value = "info", required = false) String info) {

		return departmentService.addOrUpdateDep(depId, name, info);
	}

	/**
	 * 删除部门
	 * 
	 * @param depId
	 * @return
	 */
	@PostMapping("deleteDep")
	public ResponseBody deleteDep(@RequestParam(value = "depId", required = true) Integer depId) {

		return departmentService.deleteDep(depId);
	}
}
